/*
 * 地址选择
 */
'use strict';
import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    View,
    TouchableHighlight,
    Image,
    PixelRatio,
    AsyncStorage,
    Dimensions,
    TextInput,
} from 'react-native';

import * as WechatAPI from 'react-native-wx';

import Toast from 'antd-mobile/lib/toast';
import List from 'antd-mobile/lib/list';
import Button from 'antd-mobile/lib/button';

import NavTitle from '../component/NavTitle';

import XFetch from '../XFetch';


class Deposits extends Component {
    constructor(props) {
        super(props)

        this.state = {

        }
    }

    componentDidMount(){

    }

    async _pay(){
        Toast.loading('加载中',100);
        var Token = await AsyncStorage
            .getItem('Token')
            .then(function(value){
                return Promise.resolve(value);
            }).catch(function(error){
                return Promise.reject(error);
            });
        fetch(`http://www.weiweigo.com/app/content.aspx?method=pay&type=1`,{
            method:'GET',
            headers:{
                Authorization:Token,
            }
        }).then(data=>{
            data.json().then(data=>{
                if(data){
                    Toast.hide();
                    WechatAPI.pay({
                        partnerId: String(data.partnerid),
                        prepayId: String(data.prepayid),
                        nonceStr: String(data.noncestr),
                        timeStamp: String(data.timestamp),
                        package: String(data.package),
                        sign: String(data.sign),
                    }).then(data=>{
                        Toast.success('支付成功',2);
                        this.props.navigator.pop();
                    },error=>{
                        Toast.fail('支付异常',2);
                        this.props.navigator.pop();
                    })
                }
            })
        });
    }

    render() {
        return (
            <View style={styles.container}>
                <NavTitle
                    title='缴纳保证金'
                    leftButton = {true}
                    leftImg = {require('../imgs/left.png')}
                    leftText = {'返回'}
                    leftHander = {()=>{this.props.navigator.pop()}}
                    headColor = '#fbdc3a'
                />
                <View style={styles.content}>
                    <View style={styles.Info}>
                        <View style={styles.remark}>
                            <Text style={styles.text}>在法律对于保证金缺乏明确规范的背景下，探讨保证金的类型，对于备用金类型的保证金、预付款类型的保证金、租赁保证金、装修保证金、定金类型的保证金、保有返还请求权的保证金、无双倍返还效力的保证金分别界定，确定各自的法律效力，十分必要。</Text>
                        </View>
                    </View>
                    <View style={styles.number}>
                        <View style={styles.account}>
                            <Text>
                                需要缴纳保证金:
                            </Text>
                            <Text>
                                <Text style={styles.plot}>1000.00</Text>元
                            </Text>
                        </View>
                        <Button inline onClick={this._pay.bind(this)}>立即开通</Button>
                    </View>
                </View>
            </View>
        )
    }

}

const styles = StyleSheet.create({
    container: {
        backgroundColor: '#eeeeef',
        flex: 1,
    },
    content:{

    },
    Info:{
        paddingTop:20,
        paddingBottom:20,
        paddingLeft:10,
        paddingRight:10
    },
    remark:{
        backgroundColor:'#eae2c1',
        padding:5
    },
    text:{
        lineHeight:20,
        color:'#888988',
        fontSize:16
    },
    number:{
        flexDirection:'row',
        backgroundColor:'#FFF',
        padding:15,
        paddingLeft:20
    },
    account:{
        flex:1
    },
    plot:{
        fontSize:30
    }
});

export default Deposits;
